Imports System.Data.SqlClient

Public Class TipoTelefono : Implements IBusquedaFiltrado


    Private IdTipoTel As Integer
    Private Descrip As String
    Public Property TipoTelefono() As Integer
        Get
            Return IdTipoTel
        End Get
        Set(ByVal value As Integer)
            IdTipoTel = value
        End Set
    End Property
    Public Property Descripcion() As String
        Get
            Return Descrip
        End Get
        Set(ByVal value As String)
            Descrip = value
        End Set
    End Property

    Public Sub New()
        IdTipoTel = 0
        Descrip = ""
    End Sub

    Public Function Agregar(ByRef con As ConexionBD) As Boolean Implements IBusquedaFiltrado.Agregar

        Dim sql As String = ""
        Dim comando As SqlCommand = Nothing

        sql = String.Format("INSERT INTO TipoTelefono (IdTipoTel,Decrip) VALUES({0},'{1}')", Me.IdTipoTel, Me.Descrip)
        comando = New SqlCommand(sql, con.ConexionBase)
        If comando.ExecuteNonQuery() > 0 Then
            Return True
        Else
            Return True
        End If


    End Function

    Public Function Buscar(ByVal id As Integer, ByRef con As ConexionBD) As Boolean Implements IBusquedaFiltrado.Buscar

        Dim sql As String = ""
        Dim comando As SqlCommand = Nothing
        Dim rs As SqlDataReader = Nothing
        Dim lResp As Boolean = False

        sql = String.Format("SELECT * FROM TipoTel WHERE IdTipoTel={0}", id)
        comando = New SqlCommand(sql, con.ConexionBase)
        rs = comando.ExecuteReader()
        If rs.Read() Then
            lResp = True
            Me.IdTipoTel = System.Convert.ToInt16(rs("IdTipoTel"))
            Me.Descrip = rs("Decrip").ToString
        Else
            lResp = False
        End If
        rs.Close()

        Return lResp

    End Function

    Public Function Eliminar(ByVal id As Integer, ByRef con As ConexionBD) As Boolean Implements IBusquedaFiltrado.Eliminar
        Dim sql As String = ""
        Dim comando As SqlCommand = Nothing

        sql = String.Format("DELETE FROM TipoTelefono WHERE IdTipoTel ={0}", id)
        comando = New SqlCommand(sql, con.ConexionBase)
        If comando.ExecuteNonQuery() > 0 Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function Modificar(ByRef con As ConexionBD) As Boolean Implements IBusquedaFiltrado.Modificar
        Dim sql As String = ""
        Dim comando As SqlCommand = Nothing

        sql = String.Format("UPDATE TipoTelefono SET Decrip = '{0}' WHERE IdTipoTel{1}", Me.Descrip, IdTipoTel)
        comando = New SqlCommand(sql, con.ConexionBase)
        If comando.ExecuteNonQuery() > 0 Then
            Return True
        Else
            Return False
        End If

    End Function
    Public Function BuscarId(ByVal DescTT As String, ByRef con As ConexionBD) As Boolean

        Dim comando As SqlCommand
        Dim rs As SqlDataReader
        Dim sql As String
        Dim lResp As Boolean = False

        sql = String.Format("SELECT * FROM TIPOTELEFONO WHERE Decrip='{0}'", DescTT)
        comando = New SqlCommand(sql, con.ConexionBase)
        rs = comando.ExecuteReader()
        comando.Dispose()


        If rs.Read Then
            IdTipoTel = System.Convert.ToInt16(rs("idTipoTel"))
            Descrip = rs("Decrip").ToString
            lResp = True
        Else
            lResp = False
        End If
        rs.Close()
        Return lResp

    End Function
    Public Function BuscarDatos(ByRef con As ConexionBD) As DataSet

        Dim sql As String = ""
        Dim adapter As SqlDataAdapter = Nothing
        Dim datos As DataSet = New DataSet()

        sql = "SELECT * FROM TIPOTELEFONO"
        adapter = New SqlDataAdapter(sql, con.ConexionBase)
        adapter.Fill(datos, "tipotelefono")

        Return datos
    End Function
End Class
